package com.yxinmiracle.search.controller;

import com.yxinmiracle.search.service.SkuService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.0
 * @author： YxinMiracle
 * @date： 2021-08-12 11:06
 */
@RestController
@RequestMapping("/search")
public class SkuController {

    @Autowired
    private SkuService skuService;

    @GetMapping("/import")
    public Result importToEs(){
        skuService.importSku();
        return new Result(true, StatusCode.OK,"导入成功");
    }

    /**
     * 搜索
     * @param searchMap 所有搜索的条件
     * @return
     */
    @PostMapping
    public Map<String,Object> search(@RequestBody(required = false) Map<String, String> searchMap){
        if (searchMap==null){
            searchMap = new HashMap<>();
        }
        return skuService.search(searchMap);
    }
}
